package com.cst.zju.anime.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cst.zju.anime.dao.DetailMapper;
import com.cst.zju.anime.model.Detail;
import com.cst.zju.anime.model.DetailExample;
import com.cst.zju.anime.model.DetailExample.Criteria;
import com.cst.zju.anime.model.DetailWithBLOBs;
import com.cst.zju.anime.service.IDetailService;
import com.cst.zju.anime.utils.Page;
@Transactional
@Service("iDetailService")
public class DetailService implements IDetailService {

	@Resource
	private DetailMapper detailMapper;

	@Override
	public DetailWithBLOBs getDetailById(int ID) {

		return this.detailMapper.selectByPrimaryKey(ID);
	}

	@Override
	public DetailWithBLOBs getDetailByAnimeId(int anime_id) {
		DetailExample example = new DetailExample();
		Criteria criteria = example.createCriteria();
		criteria.andAnimeIdEqualTo(anime_id);
		if(this.detailMapper.selectByExampleWithBLOBs(example).size() == 0)
			return null;
		else
			return this.detailMapper.selectByExampleWithBLOBs(example).get(0);
	}
	
	

	@Override
	public List<Detail> getDetailListForWeek(String weekday) {
		DetailExample example = new DetailExample();
		Criteria criteria = example.createCriteria();
		criteria.andStrdateLike("%"+weekday+"%");
		example.setOrderByClause("updatedate DESC");
		return this.detailMapper.selectByExample(example);
	}

	@Override
	public List<Detail> getLatestList() {
		DetailExample example = new DetailExample();
		example.setOrderByClause("updatedate desc");
		example.setPage(new Page<Detail>(0, 30));
		return this.detailMapper.selectByExample(example);
	}

	@Override
	public List<Detail> getDetailListByAnimeId(List<Integer> anime_ids) {
		DetailExample example = new DetailExample();
		Criteria criteria = example.createCriteria();
		criteria.andAnimeIdIn(anime_ids);
		return this.detailMapper.selectByExample(example);
	}
	
	

}
